package cn.edu.sjtu.dfa;

public class Move extends Instruction {
	private DataContainer endLow;
	private DataContainer startLow;
	
	public Move(DataContainer v1, DataContainer v2) {
		endLow = v1;
		startLow = v2;
	}
	
	public DataContainer getStart() {
		return startLow;
	}
	
	public DataContainer getEnd() {
		return endLow;
	}

	@Override
	public String toString() {
		String ss = "", es = "";
		if (startLow instanceof Register) {
			ss = "v" + ((Register)startLow).getRegister();
		} else if (startLow instanceof ArrayValue) {
			ss = ((ArrayValue)startLow).getArrayRef() + "[" + ((ArrayValue)startLow).getIndex() + "]";
		} else if (startLow instanceof ObjectValue) {
			ss = ((ObjectValue)startLow).getArrayRef() + "." + ((ObjectValue)startLow).getIndex();
		} else {
			ss = startLow.getValue().toString();
		}
		if (endLow instanceof Register) {
			es = "v" + ((Register)endLow).getRegister();
		} else if (endLow instanceof ArrayValue) {
			es = ((ArrayValue)endLow).getArrayRef() + "[" + ((ArrayValue)endLow).getIndex() + "]";
		} else if (endLow instanceof ObjectValue) {
			es = ((ObjectValue)endLow).getArrayRef() + "." + ((ObjectValue)endLow).getIndex();
		} else {
			ss = endLow.getValue().toString();
		}
		return "Move " + ss + " to " + es;
	}
}
